package app.displayTree.fixer.texture {
    import copyengine.infoTree.meta.CESTextureMeta;
    import copyengine.utils.packerbox.CEPackerBuilder;
    import copyengine.utils.packerbox.box.ICEPackerBox;
    import copyengine.utils.packerbox.data.CEPackerElementData;

    public final class TextureMetaFixer {
        public function TextureMetaFixer() {
        }

        private var mAllTextrueMetaVector:Vector.<CESTextureMeta>;
        private var mBuilder:CEPackerBuilder;

        /**
         *修正所有的纹理信息,因为目前纹理不是所有都Cache到一张图片上,
         *(由PackerBuilder分成多个纹理),但是这些信息在anylise时候是无法知道的(当前bitmapdata被放在了哪张纹理上)
         * 需要在Builder把所有纹理分完箱子以后再设置
         *
         */
        public function fixTextureMetaProperty(_allTextrueMetaVector:Vector.<CESTextureMeta>, _builder:CEPackerBuilder):void {
            mAllTextrueMetaVector = _allTextrueMetaVector;
            mBuilder = _builder;
            for each (var box:ICEPackerBox in mBuilder.getAllPackerBoxVector()) {
                for each (var element:CEPackerElementData in box.getAllBoxElement()) {
                    setTextureFileNameByKeyName(element.bitmapDataName, box.getBoxName());
                }
            }
        }

        private function setTextureFileNameByKeyName(_keyName:String, _fileName:String):void {
            for each (var meta:CESTextureMeta in mAllTextrueMetaVector) {
                if (meta.textureKey == _keyName) {
                    meta.textureFileName = _fileName;
                    //return; 不能Return 因为Dic里面会有多个重复的纹理
                }
            }
        }

    }
}
